<template>
	<view class="alterNickName">
		<view class="alterNickName-plate-1">
			<input type="text" v-model="nickName" placeholder="请输入昵称" />
		</view>
		<view class="alterNickName-plate-2">
			<text>{{nickName.length}}/10</text>
		</view>
		<button class="bg-btn" @click="onSave">保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickName:''
			}
		},
		onLoad(option) {
			this.nickName = option.nickName
		},
		methods: {
			//保存资料
			onSave(){
				if(this.nickName.length <= 10){
					uni.request({
					    url:this.$Url +'/index.php/App/Users/editInfo',
					    method:'POST',
					    data:{
					       nickname:this.nickName,
					    },
					    header:{
					        "token":uni.getStorageSync('token')
					    },
					    success: (res) => {
							if(res.data.status == 200){
								uni.showToast({
									title:'修改成功',
									icon:'success'
								})
								setTimeout(()=>{
									uni.redirectTo({
										url:'../userInfo'
									})
								},1500)
							}else{
								uni.showToast({
									title:res.data.msg,
									icon:'none'
								})
							}
					    }
					})
				}else{
					uni.showToast({
						title:'昵称不能超过10个字符',
						icon:'none'
					})
				}

			}
		}
	}
</script>

<style scoped lang="scss">
.alterNickName{
	width: 100vw;
	background-color: #f7f7f7;
	min-height: 100vh;
	.alterNickName-plate-1{
		height: 100upx;
		background-color: #fff;
		display: flex;
		align-items: center;
		padding-left: 30upx;
		border: none;
		input{
			color: #333;
			font-size: 28upx;
		}
	}
	.alterNickName-plate-2{
		display: flex;
		justify-content: flex-end;
		height: 60upx;
		color: #666;
		font-size: 26upx;
		padding-right: 30upx;
	}
	.bg-btn{
		width: 350upx;
		height: 90upx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 60upx;
	}
}
</style>
